﻿#region Using Directives

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections.Generic;

using QuickDev.Common.Audit;

using QuickDev.Localization;
using QuickDev.Web.UI;

using QuickDev.Model;
using QuickDev.Caching;

#endregion

namespace QuickDev.Web.App.Administration
{
    public partial class Default : AdminPage
    {
        #region Member Variables

        //int customerTypeId = 0;

        #endregion

        #region Page Events

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load( object sender, EventArgs e )
        {
            try
            {
                SetDefaulProperties();
                if ( !Page.IsPostBack )
                {
                    LoadBroadcast();

                    LoadMessageStats();
                }
            }
            catch ( Exception ex )
            {
                Logger.Error( typeof( Default ).Name + ".Page_Load", ex );
                Master.MessageCenter.DisplayCriticalMessage( ex.Message );
            }
        }

        #endregion

        #region Methods

        #region Protected

        /// <summary>
        /// Formats the edit URL.
        /// </summary>
        /// <param name="productId">The status id.</param>
        /// <returns></returns>
        protected string FormatMessageListUrl( string statusId )
        {
            return string.Format( "~/Administration/ReturnOrderList.aspx?orderStatusId={0}" , statusId );
        }

        #endregion

        #region Private

        /// <summary>
        /// Loads the search terms.
        /// </summary>
        private void LoadBroadcast()
        {
            this.lblBroadcast.Text = Master.SiteSettings.Broadcast;
        }

        /// <summary>
        /// Sets the default properties.
        /// </summary>
        private void SetDefaulProperties()
        {
            this.Title = string.Format( WebUtility.MainTitleTemplate, Master.SiteSettings.SiteName, LocalizationUtility.GetText( "titleDashBoard" ) );
        }

        /// <summary>
        /// Loads the search terms.
        /// </summary>
        private void LoadMessageStats()
        {
            dgMessageStats.DataSource = ReturnOrderStatusCache.QuickStats();
            dgMessageStats.Columns[0].HeaderText = LocalizationUtility.GetText( "hdrMessageStatus" );
            dgMessageStats.Columns[1].HeaderText = LocalizationUtility.GetText( "hdrTotalMessages" );
            dgMessageStats.DataBind();
        }

        #endregion

        #endregion

    }
}
